package com.yinhe.module.dr;

import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.core.domain.entity.SysUser;
import com.yinhe.common.core.domain.model.LoginUser;
import com.yinhe.common.core.page.TableDataInfo;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.system.domain.YhDailyquality;
import com.yinhe.system.service.IYhDailyqualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 日常质量问题报Controller
 *
 * @author dr
 * @date 2022-07-14
 */
@RestController
@RequestMapping("/dr/dailyquality")
public class DrDailyqualityController extends BaseController
{
    @Autowired
    private IYhDailyqualityService yhDailyqualityService;

    /**
     * 查询日常质量问题报列表
     */
    @PreAuthorize("@ss.hasPermi('dr:dailyquality:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhDailyquality yhDailyquality)
    {
        startPage();
        List<YhDailyquality> list = yhDailyqualityService.selectYhDailyqualityList(yhDailyquality);
        return getDataTable(list);
    }

    /**
     * 导出日常质量问题报列表
     */
    @PreAuthorize("@ss.hasPermi('dr:dailyquality:export')")
    @Log(title = "日常质量问题报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhDailyquality yhDailyquality)
    {
        List<YhDailyquality> list = yhDailyqualityService.selectYhDailyqualityList(yhDailyquality);
        ExcelUtil<YhDailyquality> util = new ExcelUtil<YhDailyquality>(YhDailyquality.class);
        util.exportExcel(response, list, "日常质量问题报数据");
    }

    /**
     * 获取日常质量问题报详细信息
     */
    @PreAuthorize("@ss.hasPermi('dr:dailyquality:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhDailyqualityService.selectYhDailyqualityById(id));
    }

    /**
     * 新增日常质量问题报
     */
    @PreAuthorize("@ss.hasPermi('dr:dailyquality:add')")
    @Log(title = "日常质量问题报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhDailyquality yhDailyquality)
    {
        // 获取当前登录用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getUser();
        // 存入userId和deptId，做数据权限
        yhDailyquality.setUserId(sysUser.getUserId());
        yhDailyquality.setDeptId(sysUser.getDeptId());
        return toAjax(yhDailyqualityService.insertYhDailyquality(yhDailyquality));
    }

    /**
     * 修改日常质量问题报
     */
    @PreAuthorize("@ss.hasPermi('dr:dailyquality:edit')")
    @Log(title = "日常质量问题报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhDailyquality yhDailyquality)
    {
        return toAjax(yhDailyqualityService.updateYhDailyquality(yhDailyquality));
    }

    /**
     * 删除日常质量问题报
     */
    @PreAuthorize("@ss.hasPermi('dr:dailyquality:remove')")
    @Log(title = "日常质量问题报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhDailyqualityService.deleteYhDailyqualityByIds(ids));
    }
}
